
package net.knightwatch.kwtools.customers;
import java.util.ArrayList;
import net.knightwatch.kwtools.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CustomerArrayAdapter extends ArrayAdapter<Customer> {
	public static final String TAG = "CustomerAdapter";
	int resource;
	String response;
	Context context;
	/**
	 * Default constructor for CustomerAdapter
	 * @param context
	 * @param resource
	 * @param customers
	 */
	public CustomerArrayAdapter(Context context, int resource, ArrayList<Customer> customers){
		super(context, resource, customers);
		this.resource=resource;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		LinearLayout customerView;
		// Get the Current customer object
		Customer customer = getItem(position);
		
		//Inflate the view
		if(convertView == null){
			customerView = new LinearLayout(getContext());
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi;
			vi = (LayoutInflater)getContext().getSystemService(inflater);
			vi.inflate(resource, customerView, true);
		}
		else
		{
			customerView = (LinearLayout) convertView;
		}
			//Get the text boxes from the listitem.xml file
	        TextView customerName =(TextView)customerView.findViewById(R.id.txtCustomerName);
	        customerName.setText(customer.getCustomerName());
	        return customerView;
		}
}
